package com.hcrazy.manchester.app.services;

import java.util.ArrayList;
import java.util.List;

import com.hcrazy.manchester.app.jdbc.CityDAO;
import com.hcrazy.manchester.app.jdbc.UserDAO;
import com.hcrazy.manchester.app.pojo.City;
import com.hcrazy.manchester.app.pojo.UserInfo;

public class CityService {

	private CityDAO cityDAO;

	public CityDAO getCityDAO() {
		return cityDAO;
	}

	public void setCityDAO(CityDAO cityDAO) {
		this.cityDAO = cityDAO;
	}
	
	private UserDAO userDAO;
	
	public UserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	public List<City> getAllCities(boolean hot) throws Exception{
		List<City> cities = cityDAO.getAllCities();
		List<UserInfo> infos = userDAO.getAllUsersHaveCity();
		
		List<City> cityList = new ArrayList<City>();
		for(City city:cities){
			int count = 0;
			for(UserInfo info:infos){
				if(info.getCityId() == city.getCityId()){
					count++;
				}
			}
			city.setMembers(count);
			if(hot){
				if(count >= 10){
					cityList.add(city);
				}
			}else{
				cityList.add(city);
			}
			
		}
		
		return cityList;
	}
}
